<template>
{{#if ctrl.psSysPFPlugin}}
  {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
    <AppForm
		ref="editForm"
        v-bind="$attrs"
		:id="controlID"
		:name="model.codeName"
		:class="classNames"
		:data="store.data"
	{{#or ctrl.width ctrl.height}}
		style="{{#if ctrl.width}}width: {{ctrl.width}}px;{{/if}}{{#if ctrl.height}}height: {{ctrl.height}}px;{{/if}}"
	{{/or}}
		>
        <AppAnchor v-if="store.anchorData.length > 0" :controlID="controlID" :anchorData="store.anchorData" />
    {{#if ctrl.noTabHeader}}
        <div class="control-content app-control-form__content">
        {{#each ctrl.psDEFormPages as | ctrlPage | }}
			<AppRow :layoutOpts="{{> @macro/common/layoutPos.hbs layout=ctrlPage.psLayout layoutPos=ctrlPage.psLayoutPos}}">
			{{#each ctrlPage.psDEFormDetails as | formDetail | }}
				{{> @macro/widgets/form-detail/include-form.hbs type=formDetail.detailType item=formDetail}}
			{{/each }}
			</AppRow>
        {{/each}}
        </div>
  {{else}}
		<a-row class="control-content app-control-form__content">
			<a-tabs class="app-control-form__page">
		    {{#each ctrl.psDEFormPages as | ctrlPage | }}
				{{> @macro/widgets/form-detail/include-form.hbs type=ctrlPage.detailType item=ctrlPage}}
		    {{/each}}
			</a-tabs>
		</a-row>
    {{/if}}
    </AppForm>
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@FORM}}-form/\{{spinalCase ctrl.codeName}}-form.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
{{importPlugin 'form' ctrl}}
import { Ref } from 'vue';
import { AppAnchor } from '@components/common/anchor';
import { AppCol } from '@/components/common/col';
import { AppRow } from '@/components/common/row';
{{#if ctrl.psDEFormPages}}
{{#each ctrl.psDEFormPages as | FormPage | }}
{{> @macro/widgets/form-detail/include-form.hbs type="FORMMDCTRLIMPORT" item=FormPage}}
{{/each}}
{{/if}}
import { AppForm, AppFormPage, AppFormGroup, AppFormTabPage, AppFormItem, AppFormButton, AppFormDruipart, AppFormIframe, AppFormRaw, AppFormMdCtrl, AppFormMdCtrlRepeater } from '@components/widgets/form';
import { model } from './{{spinalCase ctrl.codeName}}-form-model';
import { {{pascalCase ctrl.name }}ControlVO } from './{{spinalCase ctrl.codeName}}-form-vo';
import { EditFormActionType, EditFormController, IContext, IEditFormAbility, IEditFormControllerParams, IEditFormStore, IParam, ICtrlDataAction, IEditFormController, createUUID, ILoadingHelper, IViewCtx, IEvent } from '@/core';
import { useNavParamsBind, useEventBind, handleComponentAction, getCtrlClassNames } from '@/hooks/use-ctrl';
import FormService from "@/core/modules/ctrl-service/form-service";
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;
    isEditable?: boolean;
    autoLoad?: boolean;
    localMode?: boolean"
    propsDefault="isEditable: false,
    autoLoad: false,
    localMode: false"
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="EditFormActionType" ability="IEditFormAbility"}}

const editForm: Ref = ref(null);

const controlID = 'id' + createUUID();

const classNames = computed(() => {
  return getCtrlClassNames(model, props);
});

const { entityCodeName, keyPSAppDEField, majorPSAppDEField } = model;

const ctrlService = new FormService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName);
//  表单控制器
const params: IEditFormControllerParams<EditFormActionType, IEditFormAbility> = {
	name: props.name,
	model,
	evt,
	controlID,
    autoLoad: props.autoLoad,
	isEditable: props.isEditable,
	pLoadingHelper: props.pLoadingHelper,
	actions: props.actions,
	openView: props.openView,
	newView: props.newView,
	closeView: props.closeView,
	ctrlService: ctrlService,
	pViewCtx: props.pViewCtx,
	formValidate: async () => { return await editForm.value.formValidate() },
	formValidateFields: async (name: string[]) => { return await editForm.value.formValidateFields(name); },
	handler: (data: IEditFormStore) => { return reactive(data) }
};
{{> @macro/common/controller.hbs name="ctrl" IController="IEditFormController" store="IEditFormStore" ability="IEditFormAbility" controller="EditFormController"}}
</script>